﻿using System;
using System.Collections.Generic;
using System.Linq;

using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Sustainalytics.PregenerateScreeningReports.Tests
{
    [TestClass()]
    public class ScreeningReportsDistributionLogicTests
    {
        [TestMethod()]
        public void EQUALWeights_EvenPartitionTest()
        {
            var max = 600;
            var split = 10;
            var input = new List<Tuple<int, Guid>>();
            for (int i = 0; i < max; i++)
                input.Add(new Tuple<int, Guid>(5, Guid.NewGuid()) );


            var output = ScreeningReportsDistributionLogic.EvenPartition<Guid>(split, input);


            foreach(var o in output)
                 Assert.AreEqual(o.Count(), max/split );

        }


        [TestMethod()]
        public void ProgresiveWeights_EvenPartitionTest()
        {
            var max = 500;
            var split = 10;
            var input = new List<Tuple<int, Guid>>();
            for (int i = 0; i < max; i++)
                input.Add(new Tuple<int, Guid>(i, Guid.NewGuid()));


            var output = ScreeningReportsDistributionLogic.EvenPartition<Guid>(split, input);


            foreach (var o in output)
                Assert.AreEqual(o.Count(), max / split);

        }


        [TestMethod()]
        public void InequalWeights_EvenPartitionTest()
        {
            var max = 500;
            var split = 10;
            var input = new List<Tuple<int, Guid>>();

            for (int i = 0; i < max; i++)
                input.Add(new Tuple<int, Guid>(i, Guid.NewGuid()));

            for (int i = 0; i < split/2; i++)
                input.Add(new Tuple<int, Guid>(1, Guid.NewGuid()));
            


            var output = ScreeningReportsDistributionLogic.EvenPartition<Guid>(split, input);


            var count1 = output.Count(x => x.Count() == (max / split));
            var count2 = output.Count(x => x.Count() == ((max / split) + 1));

            
            Assert.AreEqual( count1 , split / 2);
            Assert.AreEqual( count2, split / 2);

        }

        [TestMethod()]
        public void OddnumberWeights_EvenPartitionTest()
        {
            var max = 11;
            var split = 2;
            var input = new List<Tuple<int, Guid>>();

            var random = new Random();
            for (int i = 0; i < max; i++)
                input.Add(new Tuple<int, Guid>(random.Next(1000), Guid.NewGuid()));
            
            var output = ScreeningReportsDistributionLogic.EvenPartition<Guid>(split, input)
                                                            .OrderBy(x =>  x.Count()).ToList();


             Assert.AreEqual(output[0].Count(), max / split);
             Assert.AreEqual(output[1].Count(), (max / split) + 1);

        }
    }
}
